/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-04-30
 * Time: 16:31
 */
//字符串常量池
public class Test {

    public static void main(String[] args) {
        String str1 = "hello";
        String str2 = "hello";

        String str3 = new String("word");
        String str4 = new String("word");

        System.out.println(str1 == str2);
        System.out.println(str3 == str4);

        System.out.println("================");

        /*char[] ch1 = new char[] {'a', 'b', 'c'};
        String s1 = new String(ch1);
        String s2 = "abc";
        System.out.println(s1 == s2);*/

        System.out.println("================");

        char[] ch2 = new char[] {'a', 'b', 'c'};
        String s3 = new String(ch2);
        s3.intern();//调用之后会把s1对象的引用放到字符串常量池中
        String s4 = "abc";
        System.out.println(s3 == s4);
    }
}
